package cn.itsource.ymcc.feign;


import cn.itsource.result.JSONResult;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "service-course",fallbackFactory = CourseClientFallbackFactory.class,contextId = "CommonFeignApi")
public interface CourseClient {

    @RequestMapping(value="/course/info/{courseIds}",method= RequestMethod.GET)
    JSONResult course2OrderInfo(@PathVariable("courseIds") String courseIds);
}


@Component
class CourseClientFallbackFactory implements FallbackFactory<CourseClient> {

    @Override
    public CourseClient create(Throwable throwable) {
        return new CourseClient() {
            @Override
            public JSONResult course2OrderInfo(String courseIds) {
                throwable.printStackTrace();
                return JSONResult.error("课程服务不可达！！");
            }
        };
    }
}
